package com.hsmw.schedule.service;

import cn.hutool.core.collection.CollectionUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;


import com.hsmw.common.base.BaseService;
import com.hsmw.domain.*;

import com.hsmw.schedule.mapper.HsmwUserDriverMapper;
import com.htn.common.core.constant.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * @author WD
 */
@Service
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class HsmwUserDriverService extends BaseService<HsmwUserDriverMapper, HsmwUserDriver> {

	@Autowired
	private HsmwReportService hsmwReportService;

	@Autowired
	private HsmwUserDriverMapper hsmwUserDriverMapper;




	public List<HsmwUserDriver> selectAvaliableList(String vehicleId){
		List<HsmwUserDriver> drivers=  hsmwUserDriverMapper.selectList(new LambdaQueryWrapper<HsmwUserDriver>()
				.eq(HsmwUserDriver::getWorkStatus,CommonConstants.DRIVER_ACCEPT_ORDER)
				.eq(HsmwUserDriver::getVehicleId,vehicleId));
		if(CollectionUtil.isNotEmpty(drivers)){
			Iterator<HsmwUserDriver> iterator = drivers.iterator();
			while (iterator.hasNext()) {
				HsmwUserDriver hsmwUserDriver = iterator.next();
				HashMap param = new HashMap();
				param.put("driverId",hsmwUserDriver.getId());
				if (hsmwReportService.checkDriverHasleavingRecord(param)) {
					iterator.remove();
				}
			}
		}
		return drivers;
	}

}
